package cumeo89.chii.client.wikt;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;

import cumeo89.chii.client.mw.Page;
import cumeo89.chii.client.util.AsyncCallback;

public class FakeWiktionary extends Wiktionary {
	
	@Override
	public void edit(String title, final AsyncCallback<Page> callback) {
//		callback.onSuccess(new Page("set"));
		try {
			RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "/set.short.html");
			rb.sendRequest("", new RequestCallback() {
			
				public void onResponseReceived(Request request, Response response) {
					Page page= new Page("set");
					page.setContent(response.getText());
					callback.onSuccess(page);
				}
			
				public void onError(Request request, Throwable exception) {
					exception.printStackTrace();
//					callback.onFailure(exception);
				}
			});
		} catch (RequestException e) {
			e.printStackTrace();
//			callback.onFailure(e);
		}
	}
	
	@Override
	public void preview(Page page, AsyncCallback<String> callback) {
		callback.onSuccess("Rởm thoai ;-)");
	}
	
	@Override
	public void save(Page page, AsyncCallback<Void> callback) {
		callback.onSuccess(null);
	}
	
}
